home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / usenet / vmsnet / empclint / part08 < prev   
Encoding:
Internet Message Format  |  1992-04-12  |  51.0 KB

  1. Path: uunet!mcsun!news.funet.fi!hydra!klaava!hurtta
  2. From: Kari.Hurtta@Helsinki.FI (Kari. E. Hurtta)
  3. Newsgroups: vmsnet.sources.games
  4. Subject: BSD Empire Client for VMS, part 8/8
  5. Message-ID: <1992Apr12.182146.15622@klaava.Helsinki.FI>
  6. Date: 12 Apr 92 18:21:46 GMT
  7. Sender: hurtta@klaava.Helsinki.FI (Kari Hurtta)
  8. Followup-To: vmsnet.sources.d
  9. Organization: University of Helsinki
  10. Lines: 1718
  11.  
  12. Archive-name: empireclient_110/part8
  13. Author: Kari.Hurtta@Helsinki.FI (Kari E. Hurtta)
  14. Product: Empire Client for VMS
  15. Version: 1.10
  16.  
  17. -+-+-+-+-+-+-+-+ START OF PART 8 -+-+-+-+-+-+-+-+
  18. X    if (food == UNKNOWN_num `124`124 civ == UNKNOWN_num `124`124 uw == UNKNO
  19. VWN_num
  20. X`009`124`124 fert == UNKNOWN_num `124`124 mil == UNKNOWN_num)
  21. X`009return 0;   /* no information */
  22. X
  23. X    left = food;
  24. X   `032
  25. X    /* production food */
  26. X    temp = VD_update_etu * ( VD_pro_food * fert / 100.0);
  27. X    /* harvest food */
  28. X    temp2 = VD_update_etu * ( VD_harv_food * (civ + uw) / 1000.0 +
  29. X`009VD_harv_food * civ / 1000.0 / 5);   /*      `094`094   ??? */
  30. X
  31. X    if (temp > temp2) temp = temp2;
  32. X   `032
  33. X    left += temp;
  34. X
  35. X    /* people eats */
  36. X    left -= VD_update_etu * ((civ + uw + mil) / 1000.0 * VD_use_food);
  37. X
  38. X   `032
  39. X    if (left < 0) return 1; /* don't birth any */
  40. X
  41. X    /* can use only half of food */
  42. X    left /= 2;
  43. X
  44. X    *civ_b = VD_update_etu * (civ / 1000.0 * VD_pro_civ);
  45. X    *uw_b  = VD_update_etu * (uw / 1000.0 * VD_pro_uw);
  46. X
  47. X    if (civ > MAX_POP) *civ_b = 0;
  48. X    else if (civ + *civ_b > MAX_POP) *civ_b = MAX_POP - civ;
  49. X
  50. X    if (uw > MAX_POP) *uw_b = 0;
  51. X    else if (uw + *uw_b > MAX_POP) *uw_b = MAX_POP - uw;
  52. X
  53. X    if (left < *civ_b / 1000.0 * VD_buse_food)`032
  54. X`009*civ_b = left * 1000.0 / VD_buse_food;
  55. X    left -= *civ_b / 1000.0 * VD_buse_food;
  56. X
  57. X    if (left < *uw_b / 1000.0 * VD_buse_food)
  58. X`009*uw_b = left * 1000.0 / VD_buse_food;
  59. X    left -= *uw_b / 1000.0 * VD_buse_food;
  60. X   `032
  61. X    return 1;
  62. X`125
  63. X
  64. Xstatic int check_desig(sector_data *sector,int *comm, int *peff)
  65. X`123
  66. X    char des = (*sector)`091F_des`093.U_num;
  67. X    int eff   = (*sector)`091F_eff`093.U_num;
  68. X    dump_fields  field;
  69. X    int i;
  70. X
  71. X    if (des == UNKNOWN_char `124`124 eff == UNKNOWN_num) return 0;
  72. X
  73. X    *comm = -1;
  74. X    *peff = 0;
  75. X
  76. X    for (i = 0; i < sizeof(commodities) / sizeof(struct COMMODITY); i++)`032
  77. X`009if (commodities`091i`093.des == des) `123
  78. X`009    *comm = i;
  79. X`009    break;
  80. X`009`125
  81. X
  82. X    if (*comm == -1) return -1;
  83. X    field = commodities`091*comm`093.ore;
  84. X    if (field == F_NULL) return -1;
  85. X
  86. X    *peff = (*sector)`091field`093.U_num;
  87. X    if (*peff == UNKNOWN_num) return 0;
  88. X    return 1;
  89. X`125
  90. X   `032
  91. Xstatic int C_desigcheck(char *comm, char *param)`032
  92. X`123
  93. X    char buffer`091COMMAND_SIZE`093,buffer2`091COMMAND_SIZE`093,buffer3`091C
  94. VOMMAND_SIZE`093;
  95. X    selector table;
  96. X    dump_fields field;
  97. X    int i,j,counter=0,var = -1;
  98. X    int all = 0;
  99. X
  100. X    if (*param == '\0' `124`124 StrEQ(param,"?",0)) `123
  101. X`009write_line("Usage: desigcheck area ?selector all =$var",E_none,NULL);
  102. X`009write_line("       desigcheck area ?selector all +$var",E_none,NULL);
  103. X`009return 1;
  104. X    `125
  105. X    InitSelector(table);
  106. X
  107. X    stepper(¶m,buffer,sizeof(buffer));
  108. X    if (!Base(&dump_database,table,buffer)) return 1; /* reask prompt */
  109. X
  110. X    stepper(¶m,buffer,sizeof(buffer));
  111. X    if (*buffer == '?') `123
  112. X`009if (!Filter(&dump_database,table,buffer)) return 1; /* reask prompt */
  113. X`009stepper(¶m,buffer,sizeof(buffer));
  114. X    `125
  115. X
  116. X    if (StrEQ(buffer,"all",1)) `123
  117. X`009all = 1;
  118. X`009stepper(¶m,buffer,sizeof(buffer));
  119. X    `125
  120. X    else if (StrEQ(buffer,"",1) `124`124 buffer`0910`093 == '=' `124`124 buf
  121. Vfer`0910`093 == '+')`032
  122. X`009all = 0;
  123. X    else write_line("bad parameter",E_tool,buffer);
  124. X
  125. X    if (strlen(buffer) && init_var(&var,buffer) == -1) return 1;
  126. X
  127. X    sprintf(buffer,"Sector  des comm peff");
  128. X    write_line(buffer,E_none,NULL);
  129. X
  130. X    for(i = 0; i < dump_database.count; i++)`032
  131. X`009if (table`091i`093) `123
  132. X`009    int peff,comm,code;
  133. X`009    sprintf(buffer,"%3d,%-3d %c   ",
  134. X`009`009dump_database.sectors`091i`093`091F_x`093.U_num,
  135. X`009`009dump_database.sectors`091i`093`091F_y`093.U_num,
  136. X`009`009dump_database.sectors`091i`093`091F_des`093.U_char);
  137. X
  138. X`009    if (code = check_desig(&dump_database.sectors`091i`093,&comm,&peff))
  139. V `123
  140. X`009`009if (code < 0) `123
  141. X`009`009    if (comm < 0) sprintf(buffer3,"          Not checked");
  142. X`009`009    else sprintf(buffer3,"%c         Not checked",
  143. X`009`009`009commodities`091comm`093.C);
  144. X`009`009`125 else `123
  145. X`009`009    sprintf(buffer3,"%c    %-3d ",
  146. X`009`009`009commodities`091comm`093.C,peff);
  147. X`009`009    if (peff > 5) strcpy(buffer2," OK");
  148. X`009`009    else `123
  149. X`009`009`009sprintf(buffer2," Will not produce much %s",
  150. X`009`009`009    commodities`091comm`093.name);
  151. X`009`009`009add_to_var(var,
  152. X`009`009`009    dump_database.sectors`091i`093`091F_x`093.U_num,
  153. X`009`009`009    dump_database.sectors`091i`093`091F_y`093.U_num);
  154. X`009`009    `125
  155. X`009`009    strcat(buffer3,buffer2);
  156. X`009`009`125
  157. X`009    `125 else `123
  158. X`009`009sprintf(buffer3,"          No information");
  159. X`009`009peff = 0;
  160. X`009`009comm = -1;
  161. X`009    `125
  162. X
  163. X`009    strcat(buffer,buffer3);
  164. X`009    if ((peff < 6 && comm >= 0) `124`124 all)
  165. X`009    write_line(buffer,E_none,NULL);
  166. X`009`125   `032
  167. X    return 1; /* reask prompt */
  168. X`125
  169. X
  170. X
  171. Xstatic int C_foodcheck(char *comm, char *param)`032
  172. X`123
  173. X    char buffer`091COMMAND_SIZE`093,buffer2`091COMMAND_SIZE`093,buffer3`091C
  174. VOMMAND_SIZE`093;
  175. X    selector table;
  176. X    dump_fields field;
  177. X    int i,j,counter=0,var = -1;
  178. X    int all = 0;
  179. X
  180. X    if (*param == '\0' `124`124 StrEQ(param,"?",0)) `123
  181. X`009write_line("Usage: foodcheck area ?selector all =$var",E_none,NULL);
  182. X`009write_line("       foodcheck area ?selector all +$var",E_none,NULL);
  183. X`009return 1;
  184. X    `125
  185. X    InitSelector(table);
  186. X
  187. X    stepper(¶m,buffer,sizeof(buffer));
  188. X    if (!Base(&dump_database,table,buffer)) return 1; /* reask prompt */
  189. X
  190. X    stepper(¶m,buffer,sizeof(buffer));
  191. X    if (*buffer == '?') `123
  192. X`009if (!Filter(&dump_database,table,buffer)) return 1; /* reask prompt */
  193. X`009stepper(¶m,buffer,sizeof(buffer));
  194. X    `125
  195. X
  196. X    if (StrEQ(buffer,"all",1)) `123
  197. X`009all = 1;
  198. X`009stepper(¶m,buffer,sizeof(buffer));
  199. X    `125
  200. X    else if (StrEQ(buffer,"",1) `124`124 buffer`0910`093 == '=' `124`124 buf
  201. Vfer`0910`093 == '+')`032
  202. X`009all = 0;
  203. X    else write_line("bad parameter",E_tool,buffer);
  204. X
  205. X    if (strlen(buffer) && init_var(&var,buffer) == -1) return 1;
  206. X
  207. X    sprintf(buffer,"Sector  des food");
  208. X    write_line(buffer,E_none,NULL);
  209. X
  210. X    for(i = 0; i < dump_database.count; i++)`032
  211. X`009if (table`091i`093) `123
  212. X`009    int left;
  213. X`009    sprintf(buffer,"%3d,%-3d %c  ",
  214. X`009`009dump_database.sectors`091i`093`091F_x`093.U_num,
  215. X`009`009dump_database.sectors`091i`093`091F_y`093.U_num,
  216. X`009`009dump_database.sectors`091i`093`091F_des`093.U_char);
  217. X`009    Text(&dump_database.sectors`091i`093,F_food,buffer2);
  218. X`009    sprintf(buffer3," %4s ",buffer2);
  219. X`009    strcat(buffer,buffer3);
  220. X
  221. X`009    if (check_food(&dump_database.sectors`091i`093,&left)) `123
  222. X`009`009if (left < 0) `123
  223. X`009`009    sprintf(buffer3,"Need %d unit%s food",
  224. X`009`009    -left, -left == 1 ? "": "s" );
  225. X`009`009    add_to_var(var,
  226. X`009`009`009dump_database.sectors`091i`093`091F_x`093.U_num,
  227. X`009`009`009dump_database.sectors`091i`093`091F_y`093.U_num);
  228. X`009`009`125
  229. X`009`009if (left > 0) sprintf(buffer3,"%d unit%s food left",
  230. X`009`009    left, left == 1 ? "" : "s" );
  231. X`009`009if (left == 0) sprintf(buffer3,"ok");
  232. X`009    `125 else `123
  233. X`009`009sprintf(buffer3,"No information");
  234. X`009`009left = 0;
  235. X`009    `125
  236. X
  237. X`009    strcat(buffer,buffer3);
  238. X`009    if (left < 0 `124`124 all)
  239. X`009    write_line(buffer,E_none,NULL);
  240. X`009`125   `032
  241. X    return 1; /* reask prompt */
  242. X`125
  243. X
  244. Xstatic int C_birthcheck(char *comm, char *param)`032
  245. X`123
  246. X    char buffer`091COMMAND_SIZE`093,buffer2`091COMMAND_SIZE`093,buffer3`091C
  247. VOMMAND_SIZE`093;
  248. X    selector table;
  249. X    dump_fields field;
  250. X    int i,j,counter=0,var = -1;
  251. X    int all = 0;
  252. X
  253. X    if (*param == '\0' `124`124 StrEQ (param,"?",0)) `123
  254. X`009write_line("Usage: birthcheck area ?selector all =$var",E_none,NULL);
  255. X`009write_line("       birthcheck area ?selector all +$var",E_none,NULL);
  256. X`009return 1;
  257. X    `125
  258. X    InitSelector(table);
  259. X
  260. X    stepper(¶m,buffer,sizeof(buffer));
  261. X    if (!Base(&dump_database,table,buffer)) return 1; /* reask prompt */
  262. X
  263. X    stepper(¶m,buffer,sizeof(buffer));
  264. X    if (*buffer == '?') `123
  265. X`009if (!Filter(&dump_database,table,buffer)) return 1; /* reask prompt */
  266. X`009stepper(¶m,buffer,sizeof(buffer));
  267. X    `125
  268. X
  269. X    if (StrEQ(buffer,"all",1)) `123
  270. X`009all = 1;
  271. X`009stepper(¶m,buffer,sizeof(buffer));
  272. X    `125
  273. X    else if (StrEQ(buffer,"",1) `124`124 buffer`0910`093 == '=' `124`124 buf
  274. Vfer`0910`093 == '+')`032
  275. X`009all = 0;
  276. X    else `123
  277. X`009write_line("bad parameter",E_tool,buffer);
  278. X`009return 1; /* reask prompt */
  279. X    `125
  280. X
  281. X    if (strlen(buffer) && init_var(&var,buffer) == -1) return 1;
  282. X
  283. X    sprintf(buffer,"Sector  des civ  uw");
  284. X    write_line(buffer,E_none,NULL);
  285. X
  286. X    for(i = 0; i < dump_database.count; i++)`032
  287. X`009if (table`091i`093) `123
  288. X`009    int civ,uw;
  289. X`009    sprintf(buffer,"%3d,%-3d %c  ",
  290. X`009`009dump_database.sectors`091i`093`091F_x`093.U_num,
  291. X`009`009dump_database.sectors`091i`093`091F_y`093.U_num,
  292. X`009`009dump_database.sectors`091i`093`091F_des`093.U_char);
  293. X
  294. X`009    Text(&dump_database.sectors`091i`093,F_civ,buffer2);
  295. X`009    sprintf(buffer3," %3s",buffer2);
  296. X`009    strcat(buffer,buffer3);
  297. X
  298. X`009    Text(&dump_database.sectors`091i`093,F_uw,buffer2);
  299. X`009    sprintf(buffer3," %3s",buffer2);
  300. X`009    strcat(buffer,buffer3);
  301. X
  302. X`009    if (check_baby(&dump_database.sectors`091i`093,&civ,&uw)) `123
  303. X`009`009buffer3`0910`093 = '\0';
  304. X`009`009if (civ > 0 && all) `123
  305. X`009`009    sprintf(buffer2,"%s gives %d civ%s",
  306. X`009`009`009buffer3`0910`093 ? "," : "",
  307. X`009`009`009civ, civ == 1 ? "" : "s" );
  308. X`009`009    strcat(buffer3,buffer2);
  309. X`009`009`125
  310. X`009`009if (civ <= 0 &&`032
  311. X`009`009    (all `124`124 dump_database.sectors`091i`093`091F_civ`093.U_num
  312. V > 1)) `123
  313. X`009`009    sprintf(buffer2,"%s not give any civs",
  314. X`009`009`009buffer3`0910`093 ? "," : "");
  315. X`009`009    strcat(buffer3,buffer2);
  316. X
  317. X`009`009    add_to_var(var,
  318. X`009`009`009dump_database.sectors`091i`093`091F_x`093.U_num,
  319. X`009`009`009dump_database.sectors`091i`093`091F_y`093.U_num);
  320. X`009`009`125
  321. X
  322. X`009`009if (uw > 0 && all) `123
  323. X`009`009    sprintf(buffer2,"%s gives %d uw%s",
  324. X`009`009`009buffer3`0910`093 ? "," : "",
  325. X`009`009`009uw, uw == 1 ? "" : "s" );
  326. X`009`009    strcat(buffer3,buffer2);
  327. X`009`009`125
  328. X`009`009if (uw <= 0 &&`032
  329. X`009`009    (all `124`124 dump_database.sectors`091i`093`091F_uw`093.U_num >
  330. V 1)) `123
  331. X`009`009    sprintf(buffer2,"%s not give any uws",
  332. X`009`009`009buffer3`0910`093 ? "," : "");
  333. X`009`009    strcat(buffer3,buffer2);
  334. X`009`009`125
  335. X
  336. X`009`009strcat(buffer,buffer3);
  337. X`009`009if (buffer3`0910`093) write_line(buffer,E_none,NULL);
  338. X
  339. X`009    `125 else `123
  340. X`009`009sprintf(buffer3,"  No information");
  341. X
  342. X`009`009strcat(buffer,buffer3);
  343. X`009`009if (all) write_line(buffer,E_none,NULL);
  344. X`009    `125
  345. X
  346. X`009`125   `032
  347. X    return 1; /* reask prompt */
  348. X`125
  349. X
  350. Xstatic int C_autodump(char *comm, char *param)
  351. X`123
  352. X    if (StrEQ(param,"?",0)) `123
  353. X`009write_line("Usage: autodump on/off",E_none,NULL);
  354. X`009return 1;   /* reask prompt */
  355. X    `125
  356. X
  357. X    if (!param`0910`093) `123
  358. X`009if (auto_update) write_line("Autodump is ON",E_none,NULL);
  359. X`009else write_line("Autodump is OFF",E_none,NULL);
  360. X`009return 1;   /* reask prompt */
  361. X    `125
  362. X
  363. X    if (empiretool_cancel) `123
  364. X`009write_line("Canceled.",E_tool,NULL);
  365. X`009empiretool_cancel = 0;
  366. X`009return 1;
  367. X    `125
  368. X
  369. X    if (StrEQ(param,"on",1)) `123
  370. X`009auto_update = 1;
  371. X`009cancel_updatetimer();
  372. X`009write_line("Autodump is now ON",E_none,NULL);
  373. X`009feed_command("update",parse_update);
  374. X`009return 0;  /* don't reask prompt */
  375. X    `125
  376. X
  377. X    if (StrEQ(param,"off",1)) `123
  378. X`009auto_update = 0;
  379. X`009write_line("Autodump is now OFF",E_none,NULL);
  380. X`009cancel_updatetimer();
  381. X`009return 1;   /* reask prompt */
  382. X    `125
  383. X
  384. X    write_line("Bad parameter",E_tool,param);
  385. X    return 1;`009/* reask prompt */
  386. X`125
  387. X
  388. X#define MAX_MOVE_PATH 50
  389. X
  390. Xstatic int C_move(char *comm, char *param)`032
  391. X`123
  392. X    char buffer`091COMMAND_SIZE`093;
  393. X    char path`091MAX_MOVE_PATH+2`093;
  394. X    sector_data *from,*tar,*B = dump_database.sectors;
  395. X    cost_table costtable;
  396. X    dir_table dirtable;
  397. X    int commodity,amount,mob,temp_X,temp_Y,var = -1;
  398. X    expression amount_e;
  399. X
  400. X    if (!stepper(¶m,buffer,sizeof(buffer)) `124`124 StrEQ(buffer,"?",0))
  401. V `123
  402. X`009write_line("Usage: move com from amount target =$var",E_none,NULL);
  403. X`009write_line("       move com from amount target +$var",E_none,NULL);
  404. X`009write_line("   amount can be expression (depending of target-sector)",
  405. X`009    E_none,NULL);
  406. X`009return 1;
  407. X    `125
  408. X
  409. X    if((move_field = MatchCom(buffer,&commodity)) == F_NULL) return 1;
  410. X
  411. X    if(!stepper(¶m,buffer,sizeof(buffer)) `124`124`032
  412. X`009sscanf(buffer,"%d,%d",&start_X,&start_Y) != 2) `123
  413. X`009write_line("Give sector in format X,Y",E_tool,buffer);
  414. X`009return 1;
  415. X    `125
  416. X
  417. X    if(!(from = Locate(&dump_database,start_X,start_Y))) `123
  418. X`009write_line("Sector not found",E_tool,buffer);
  419. X`009return 1;
  420. X    `125
  421. X
  422. X    amount = (*from)`091move_field`093.U_num;
  423. X    mob = (*from)`091F_mob`093.U_num;
  424. X
  425. X    if (amount == UNKNOWN_num `124`124 mob == UNKNOWN_num) `123
  426. X`009write_line("Not enaugh data for that sector",E_tool,buffer);
  427. X`009return 1;
  428. X    `125
  429. X
  430. X    if (move_field == F_civ) amount--;`009    /* not move last */
  431. X
  432. X    if(!stepper(¶m,buffer,sizeof(buffer)) `124`124`032
  433. X`009!parse_expression(&amount_e,buffer)) `123
  434. X`009write_line("No such amount",E_tool,buffer);
  435. X`009return 1;
  436. X    `125
  437. X
  438. X    if(!stepper(¶m,buffer,sizeof(buffer)) `124`124`032
  439. X`009sscanf(buffer,"%d,%d",&tar_X,&tar_Y) != 2) `123
  440. X`009write_line("Give sector in format X,Y",E_tool,buffer);
  441. X`009return 1;
  442. X    `125
  443. X
  444. X    if(!(tar = Locate(&dump_database,tar_X,tar_Y))) `123
  445. X`009write_line("Sector not found",E_tool,buffer);
  446. X`009return 1;
  447. X    `125 else if ((move_amount = execute_expression(amount_e,tar)) ==`032
  448. X`009UNKNOWN_num) `123
  449. X`009write_line("Can't calculate amount expression",E_tool,NULL);
  450. X`009return 1;
  451. X    `125 else if (move_amount <= 0) `123
  452. X`009sprintf(buffer,"%d",move_amount);
  453. X`009write_line("Non-positive amount - nothing need to move",E_tool,buffer);
  454. X`009return 1;
  455. X    `125 else if (move_amount > amount) `123
  456. X`009sprintf(buffer,"%d (only %d)",move_amount,amount);
  457. X`009write_line("No such amount to move",E_tool,buffer);
  458. X`009return 1;
  459. X    `125
  460. X
  461. X    if(stepper(¶m,buffer,sizeof(buffer)) &&
  462. X`009init_var(&var,buffer) == -1) return 1;
  463. X
  464. X    calculate_cost(&dump_database,start_X,start_Y,
  465. X`009costtable,dirtable,MAX_MOVE_PATH);
  466. X
  467. X    if (costtable`091tar - B`093 * move_amount * commodities`091commodity`09
  468. V3.mob_mul`032
  469. X`009> mob) `123
  470. X`009write_line("No enough mobility",E_tool,NULL);
  471. X`009return 1;
  472. X    `125
  473. X
  474. X    give_path(&dump_database,dirtable,path,tar - B,&temp_X,&temp_Y);
  475. X    if (temp_X != start_X `124`124 temp_Y != start_Y) `123
  476. X`009write_line("Something is wrong with path",E_tool,NULL);
  477. X`009return 1;
  478. X    `125
  479. X
  480. X    if (empiretool_cancel) `123
  481. X`009write_line("Canceled.",E_tool,NULL);
  482. X`009empiretool_cancel = 0;
  483. X`009return 1;
  484. X    `125
  485. X
  486. X    move_auto = 0;
  487. X    move_stat = 0;
  488. X    cur_mob = UNKNOWN_num;
  489. X    move_var = var;
  490. X
  491. X    sprintf(buffer,"move %c %d,%d %d %s",
  492. X`009commodities`091commodity`093.C,start_X,start_Y,move_amount,path);
  493. X    feed_command(buffer,parse_dump_move);
  494. X    return 0;`009/* no prompt */
  495. X`125
  496. X
  497. Xstatic selector move_table;
  498. Xstatic int`009move_ind = 0;
  499. Xstatic int`009move_com_i = 0;
  500. Xstatic expression move_amount_expression;
  501. X
  502. Xstatic void move_next(void)`032
  503. X`123
  504. X    char path`091MAX_MOVE_PATH+2`093;
  505. X    char buffer`091COMMAND_SIZE`093;
  506. X    sector_data *tar,*B = dump_database.sectors;
  507. X    cost_table costtable;
  508. X    dir_table dirtable;
  509. X    int amount,mob,temp_X,temp_Y;
  510. X
  511. X    int again = 1;
  512. X
  513. X    if (BTU_left <= btu_limit) `123
  514. X`009sprintf(buffer, "No BTU left - Collected %d %s%s",
  515. X`009    move_stat,commodities`091move_com_i`093.name,`032
  516. X`009    move_stat == 1 ? "" : "s");
  517. X`009write_line(buffer,E_none,NULL);
  518. X        call_empiretool_handler();
  519. X`009return;
  520. X    `125
  521. X
  522. X    while(again) `123
  523. X`009again = 0;
  524. X`009if (move_ind >= dump_database.count) `123
  525. X`009    sprintf(buffer, "Collected %d %s%s",
  526. X`009`009move_stat,commodities`091move_com_i`093.name,`032
  527. X`009`009move_stat == 1 ? "" : "s");
  528. X`009    write_line(buffer,E_none,NULL);
  529. X`009    call_empiretool_handler();
  530. X`009    return;
  531. X`009`125
  532. X
  533. X`009if (!move_table`091move_ind`093) `123
  534. X`009    again = 1;
  535. X`009    move_ind++;
  536. X`009    continue;
  537. X`009`125
  538. X
  539. X`009start_X = dump_database.sectors`091move_ind`093`091F_x`093.U_num;
  540. X`009start_Y = dump_database.sectors`091move_ind`093`091F_y`093.U_num;
  541. X
  542. X`009if (start_X == UNKNOWN_num `124`124 start_Y == UNKNOWN_num) `123
  543. X`009    again = 1;
  544. X`009    move_ind++;
  545. X`009    continue;
  546. X`009`125
  547. X
  548. X`009if (start_X == tar_X && start_Y == tar_Y) `123
  549. X`009    again = 1;
  550. X`009    move_ind++;
  551. X`009    continue;
  552. X`009`125
  553. X
  554. X`009amount = dump_database.sectors`091move_ind`093`091move_field`093.U_num;
  555. X`009mob = dump_database.sectors`091move_ind`093`091F_mob`093.U_num;
  556. X
  557. X`009if (amount == UNKNOWN_num `124`124 mob == UNKNOWN_num) `123
  558. X`009    sprintf(buffer,"Not enaugh data for sector %d,%d",
  559. X`009`009start_X,start_Y);
  560. X`009    write_line(buffer,E_tool,NULL);
  561. X`009    again = 1;
  562. X`009    move_ind++;
  563. X`009    continue;
  564. X`009`125
  565. X
  566. X`009if (move_field == F_civ) amount--;`009    /* not move last */
  567. X
  568. X`009if (amount < 1) `123
  569. X`009    sprintf(buffer,"No %s to move from sector %d,%d",
  570. X`009`009commodities`091move_com_i`093.name, start_X,start_Y);
  571. X`009    write_line(buffer,E_tool,NULL);
  572. X`009    again = 1;
  573. X`009    move_ind++;
  574. X`009    continue;
  575. X`009`125
  576. X
  577. X`009if(!(tar = Locate(&dump_database,tar_X,tar_Y))) `123
  578. X`009    write_line("Target sector not found",E_tool,NULL);
  579. X`009    call_empiretool_handler();
  580. X`009    return;
  581. X`009`125
  582. X
  583. X`009move_amount = execute_expression(move_amount_expression,
  584. X`009    dump_database.sectors`091move_ind`093);
  585. X`009if (move_amount == UNKNOWN_num) `123
  586. X `009    sprintf(buffer,"Can't calculate amount of %s to move from sector %d
  587. V,%d",
  588. X`009`009commodities`091move_com_i`093.name, start_X,start_Y);
  589. X`009    write_line(buffer,E_tool,NULL);
  590. X`009    again = 1;
  591. X`009    move_ind++;
  592. X`009    continue;
  593. X`009`125 else if (move_amount <= 0) `123
  594. X`009    sprintf(buffer,"Amount of %s to move from sector %d,%d is non-positi
  595. Vve: %d",
  596. X`009`009commodities`091move_com_i`093.name, start_X,start_Y,move_amount);
  597. X`009    write_line(buffer,E_tool,NULL);
  598. X`009    again = 1;
  599. X`009    move_ind++;
  600. X`009    continue;
  601. X`009`125`032
  602. X
  603. X`009if (move_amount > amount) `123
  604. X`009    move_amount = amount;
  605. X
  606. X`009    sprintf(buffer,"Collecting only %d %s%s from sector %d,%d",
  607. X`009`009move_amount,
  608. X`009`009commodities`091move_com_i`093.name, move_amount == 1 ? "" : "s",`032
  609. X`009`009start_X,start_Y);
  610. X`009    write_line(buffer,E_tool,NULL);
  611. X
  612. X`009`125
  613. X
  614. X`009calculate_cost(&dump_database,start_X,start_Y,
  615. X`009    costtable,dirtable,MAX_MOVE_PATH);
  616. X
  617. X`009if (costtable`091tar - B`093 * move_amount *`032
  618. X`009    commodities`091move_com_i`093.mob_mul  > mob) `123
  619. X`009    int tmp = move_amount;
  620. X
  621. X`009    if (commodities`091move_com_i`093.mob_mul`009* costtable`091tar - B`
  622. V093 > 0)
  623. X`009`009move_amount = mob /`032
  624. X`009`009    (commodities`091move_com_i`093.mob_mul* costtable`091tar - B`093
  625. V);
  626. X`009    else move_amount = 0;
  627. X
  628. X`009    if (move_amount <= 0) `123
  629. X`009`009sprintf(buffer,"Not enough mobility in sector %d,%d",
  630. X`009`009    start_X,start_Y);
  631. X`009`009write_line(buffer,E_tool,NULL);
  632. X`009`009again = 1;
  633. X`009`009move_ind++;
  634. X`009`009continue;
  635. X`009    `125 else `123
  636. X`009`009sprintf(buffer,
  637. X"Not enough mobility in sector %d,%d - moving only %d (of %d)",
  638. X`009`009    start_X,start_Y,move_amount,tmp);
  639. X`009`009write_line(buffer,E_tool,NULL);
  640. X`009    `125
  641. X`009`125
  642. X
  643. X`009give_path(&dump_database,dirtable,path,tar - B,&temp_X,&temp_Y);
  644. X`009if (temp_X != start_X `124`124 temp_Y != start_Y) `123
  645. X`009    write_line("Something is wrong with path",E_tool,NULL);
  646. X`009    call_empiretool_handler();
  647. X`009    return;
  648. X`009`125
  649. X
  650. X    `125
  651. X    move_ind++;
  652. X
  653. X    move_auto = 1; /* 1 = collect, 2 = automove */
  654. X    cur_mob = UNKNOWN_num;
  655. X    sprintf(buffer,"move %c %d,%d %d %s",
  656. X`009commodities`091move_com_i`093.C,start_X,start_Y,move_amount,path);
  657. X    feed_command(buffer,parse_dump_move);
  658. X
  659. X`125
  660. X
  661. Xstatic cost_table moveauto_costtable;
  662. Xstatic dir_table moveauto_dirtable;
  663. X
  664. X
  665. Xstatic void moveauto_next(void)`032
  666. X`123
  667. X    char path`091MAX_MOVE_PATH+2`093;
  668. X    char buffer`091COMMAND_SIZE`093;
  669. X    sector_data *from,*B = dump_database.sectors;
  670. X    int amount,mob,temp_X,temp_Y;
  671. X
  672. X    int again = 1;
  673. X
  674. X    if (BTU_left <= btu_limit) `123
  675. X`009sprintf(buffer, "No BTU left - Moved %d %s%s",
  676. X`009    move_stat,commodities`091move_com_i`093.name,`032
  677. X`009    move_stat == 1 ? "" : "s");
  678. X`009write_line(buffer,E_none,NULL);
  679. X        call_empiretool_handler();
  680. X`009return;
  681. X    `125
  682. X
  683. X    while(again) `123
  684. X`009again = 0;
  685. X`009if (move_ind >= dump_database.count) `123
  686. X`009    sprintf(buffer, "Moved %d %s%s",
  687. X`009`009move_stat,commodities`091move_com_i`093.name,`032
  688. X`009`009move_stat == 1 ? "" : "s");
  689. X`009    write_line(buffer,E_none,NULL);
  690. X`009    call_empiretool_handler();
  691. X`009    return;
  692. X`009`125
  693. X
  694. X`009if (!move_table`091move_ind`093) `123
  695. X`009    again = 1;
  696. X`009    move_ind++;
  697. X`009    continue;
  698. X`009`125
  699. X
  700. X`009tar_X = dump_database.sectors`091move_ind`093`091F_x`093.U_num;
  701. X`009tar_Y = dump_database.sectors`091move_ind`093`091F_y`093.U_num;
  702. X
  703. X`009if (tar_X == UNKNOWN_num `124`124 tar_Y == UNKNOWN_num) `123
  704. X`009    again = 1;
  705. X`009    move_ind++;
  706. X`009    continue;
  707. X`009`125
  708. X
  709. X`009if (start_X == tar_X && start_Y == tar_Y) `123
  710. X`009    again = 1;
  711. X`009    move_ind++;
  712. X`009    continue;
  713. X`009`125
  714. X
  715. X`009if(!(from = Locate(&dump_database,start_X,start_Y))) `123
  716. X`009    write_line("Sector not found",E_tool,buffer);
  717. X`009    call_empiretool_handler();
  718. X`009    return;
  719. X`009`125
  720. X
  721. X`009amount = (*from)`091move_field`093.U_num;
  722. X`009mob = (*from)`091F_mob`093.U_num;
  723. X
  724. X`009if (amount == UNKNOWN_num `124`124 mob == UNKNOWN_num) `123
  725. X`009    sprintf(buffer,"Not enaugh data for sector %d,%d",
  726. X`009`009start_X,start_Y);
  727. X`009    write_line(buffer,E_tool,NULL);
  728. X`009    call_empiretool_handler();
  729. X`009    return;
  730. X`009`125
  731. X
  732. X`009if (move_field == F_civ) amount--;`009    /* not move last */
  733. X
  734. X`009if (amount < 1) `123
  735. X`009    sprintf(buffer,"No %s to move from sector %d,%d - Moved %d %s%s",
  736. X`009`009commodities`091move_com_i`093.name, start_X,start_Y,
  737. X`009`009move_stat,commodities`091move_com_i`093.name,`032
  738. X`009`009move_stat == 1 ? "" : "s");
  739. X`009    write_line(buffer,E_tool,NULL);
  740. X`009    call_empiretool_handler();
  741. X`009    return;
  742. X`009`125
  743. X
  744. X
  745. X`009move_amount = execute_expression(move_amount_expression,
  746. X`009    dump_database.sectors`091move_ind`093);
  747. X`009if (move_amount == UNKNOWN_num) `123
  748. X `009    sprintf(buffer,"Can't calculate amount of %s to move to sector %d,%
  749. Vd",
  750. X`009`009commodities`091move_com_i`093.name, tar_X,tar_Y);
  751. X`009    write_line(buffer,E_tool,NULL);
  752. X`009    again = 1;
  753. X`009    move_ind++;
  754. X`009    continue;
  755. X`009`125 else if (move_amount <= 0) `123
  756. X`009    sprintf(buffer,"Amount of %s to move to sector %d,%d is non-positive
  757. V: %d",
  758. X`009`009commodities`091move_com_i`093.name, tar_X,tar_Y,move_amount);
  759. X`009    write_line(buffer,E_tool,NULL);
  760. X`009    again = 1;
  761. X`009    move_ind++;
  762. X`009    continue;
  763. X`009`125`032
  764. X
  765. X`009if (move_amount > amount) `123
  766. X`009    move_amount = amount;
  767. X
  768. X`009    sprintf(buffer,"Moving only %d %s%s from sector %d,%d to %d,%d",
  769. X`009`009move_amount,
  770. X`009`009commodities`091move_com_i`093.name, move_amount == 1 ? "" : "s",`032
  771. X`009`009start_X,start_Y,tar_X,tar_Y);
  772. X`009    write_line(buffer,E_tool,NULL);
  773. X`009`125
  774. X
  775. X`009if (moveauto_costtable`091move_ind`093 * move_amount *`032
  776. X`009    commodities`091move_com_i`093.mob_mul  > mob) `123
  777. X`009    int tmp = move_amount;
  778. X
  779. X`009    if (commodities`091move_com_i`093.mob_mul`009*`032
  780. X`009`009moveauto_costtable`091move_ind`093 > 0)
  781. X`009`009move_amount = mob /`032
  782. X`009`009    (commodities`091move_com_i`093.mob_mul*`032
  783. X`009`009    moveauto_costtable`091move_ind`093);
  784. X`009    else move_amount = 0;
  785. X
  786. X`009    if (move_amount <= 0) `123
  787. X`009`009sprintf(buffer,
  788. X"Not enough mobility in sector %d,%d - Moved %d %s%s",
  789. X`009`009    start_X,start_Y,
  790. X`009`009    move_stat,commodities`091move_com_i`093.name,`032
  791. X`009`009    move_stat == 1 ? "" : "s");
  792. X`009`009write_line(buffer,E_tool,NULL);
  793. X`009`009call_empiretool_handler();
  794. X`009`009return;
  795. X`009    `125 else `123
  796. X`009`009sprintf(buffer,
  797. X"Not enough mobility in sector %d,%d - moving only %d (of %d) to %d,%d",
  798. X`009`009    start_X,start_Y,move_amount,tmp,tar_X,tar_Y);
  799. X`009`009write_line(buffer,E_tool,NULL);
  800. X`009    `125
  801. X`009`125
  802. X
  803. X`009give_path(&dump_database,moveauto_dirtable,path,move_ind,&temp_X,&temp_Y
  804. V);
  805. X`009if (temp_X != start_X `124`124 temp_Y != start_Y) `123
  806. X`009    write_line("Something is wrong with path",E_tool,NULL);
  807. X`009    call_empiretool_handler();
  808. X`009    return;
  809. X`009`125
  810. X
  811. X    `125
  812. X    move_ind++;
  813. X
  814. X    move_auto = 2; /* 1 = collect, 2 = automove */
  815. X    cur_mob = UNKNOWN_num;
  816. X    sprintf(buffer,"move %c %d,%d %d %s",
  817. X`009commodities`091move_com_i`093.C,start_X,start_Y,move_amount,path);
  818. X    feed_command(buffer,parse_dump_move);
  819. X
  820. X`125
  821. X
  822. Xstatic int C_collect(char *comm, char *param)`032
  823. X`123
  824. X    char buffer`091COMMAND_SIZE`093;
  825. X    sector_data *tar;
  826. X    int btu;
  827. X
  828. X    move_var = -1;
  829. X
  830. X    if (!stepper(¶m,buffer,sizeof(buffer)) `124`124 StrEQ(buffer,"?",0))
  831. V `123
  832. X`009write_line(
  833. X`009"Usage: collect com from_area ?selector... amount target btu =$var",
  834. X`009    E_none,NULL);
  835. X`009write_line(
  836. X`009"       collect com from_area ?selector... amount target btu +$var",
  837. X`009    E_none,NULL);
  838. X`009write_line("  amount can be expression (depending of from-sector)",
  839. X`009    E_none,NULL);
  840. X`009return 1;
  841. X    `125
  842. X
  843. X    if((move_field = MatchCom(buffer,&move_com_i)) == F_NULL) return 1;
  844. X
  845. X    InitSelector(move_table);
  846. X    move_ind = 0;
  847. X
  848. X    stepper(¶m,buffer,sizeof(buffer));
  849. X    if (!Base(&dump_database,move_table,buffer)) return 1; /* reask prompt *
  850. V/
  851. X
  852. X    stepper(¶m,buffer,sizeof(buffer));
  853. X    if (*buffer == '?') `123
  854. X`009if (!Filter(&dump_database,move_table,buffer)) return 1; /* reask prompt
  855. V */
  856. X`009stepper(¶m,buffer,sizeof(buffer));
  857. X    `125
  858. X
  859. X    if(!parse_expression(&move_amount_expression,buffer)) `123
  860. X`009write_line("No such amount",E_tool,buffer);
  861. X`009return 1;
  862. X    `125
  863. X
  864. X    if(!stepper(¶m,buffer,sizeof(buffer)) `124`124`032
  865. X`009sscanf(buffer,"%d,%d",&tar_X,&tar_Y) != 2) `123
  866. X`009write_line("Give sector in format X,Y",E_tool,buffer);
  867. X`009return 1;
  868. X    `125
  869. X
  870. X    if(!(tar = Locate(&dump_database,tar_X,tar_Y))) `123
  871. X`009write_line("Sector not found",E_tool,buffer);
  872. X`009return 1;
  873. X    `125
  874. X
  875. X    btu = BTU_left - 20;
  876. X    if (btu < 0) `123
  877. X`009write_line("No BTU's for collect!",E_tool,NULL);
  878. X`009return 1;
  879. X    `125
  880. X
  881. X    if (stepper(¶m,buffer,sizeof(buffer)) &&`032
  882. X`009(sscanf(buffer,"%d",&btu) != 1 `124`124
  883. X`009    btu > BTU_left)) `123
  884. X`009write_line("No such btu",E_tool,buffer);
  885. X`009return 1;
  886. X    `125
  887. X
  888. X    if(stepper(¶m,buffer,sizeof(buffer)) &&
  889. X`009init_var(&move_var,buffer) == -1) return 1;
  890. X
  891. X    btu_limit = BTU_left - btu;
  892. X    move_ind = 0;
  893. X    move_auto = 1;
  894. X    move_stat = 0;
  895. X    move_next();
  896. X    return 0;`009/* no prompt */
  897. X`125
  898. X
  899. Xstatic int C_automove(char *comm, char *param)`032
  900. X`123
  901. X    char buffer`091COMMAND_SIZE`093;
  902. X    sector_data *from;
  903. X    int btu;
  904. X
  905. X    move_var = -1;
  906. X
  907. X    if (!stepper(¶m,buffer,sizeof(buffer)) `124`124 StrEQ(buffer,"?",0))
  908. V `123
  909. X`009write_line(
  910. X`009"Usage: automove com from amount target_area ?selector... btu =$var",
  911. X`009    E_none,NULL);
  912. X`009write_line(
  913. X`009"       automove com from amount target_area ?selector... btu +$var",
  914. X`009    E_none,NULL);
  915. X`009write_line("  amount can be expression (depending of target-sector)",
  916. X`009    E_none,NULL);
  917. X`009return 1;
  918. X    `125
  919. X
  920. X    if((move_field = MatchCom(buffer,&move_com_i)) == F_NULL) return 1;
  921. X
  922. X    stepper(¶m,buffer,sizeof(buffer));
  923. X    if(sscanf(buffer,"%d,%d",&start_X,&start_Y) != 2) `123
  924. X`009write_line("Give sector in format X,Y",E_tool,buffer);
  925. X`009return 1;
  926. X    `125
  927. X
  928. X    if(!(from = Locate(&dump_database,start_X,start_Y))) `123
  929. X`009write_line("Sector not found",E_tool,buffer);
  930. X`009return 1;
  931. X    `125
  932. X
  933. X    stepper(¶m,buffer,sizeof(buffer));
  934. X    if(!parse_expression(&move_amount_expression,buffer)) `123
  935. X`009write_line("No such amount",E_tool,buffer);
  936. X`009return 1;
  937. X    `125
  938. X
  939. X    InitSelector(move_table);
  940. X    move_ind = 0;
  941. X
  942. X    stepper(¶m,buffer,sizeof(buffer));
  943. X    if (!Base(&dump_database,move_table,buffer)) return 1; /* reask prompt *
  944. V/
  945. X
  946. X    stepper(¶m,buffer,sizeof(buffer));
  947. X    if (*buffer == '?') `123
  948. X`009if (!Filter(&dump_database,move_table,buffer)) return 1; /* reask prompt
  949. V */
  950. X`009stepper(¶m,buffer,sizeof(buffer));
  951. X    `125
  952. X
  953. X    btu = BTU_left - 20;
  954. X    if (btu < 0) `123
  955. X`009write_line("No BTU's for collect!",E_tool,NULL);
  956. X`009return 1;
  957. X    `125
  958. X
  959. X    if ((sscanf(buffer,"%d",&btu) != 1 `124`124
  960. X`009    btu > BTU_left)) `123
  961. X`009write_line("No such btu",E_tool,buffer);
  962. X`009return 1;
  963. X    `125
  964. X
  965. X    if(stepper(¶m,buffer,sizeof(buffer)) &&
  966. X`009init_var(&move_var,buffer) == -1) return 1;
  967. X
  968. X    calculate_cost(&dump_database,start_X,start_Y,
  969. X`009moveauto_costtable,moveauto_dirtable,MAX_MOVE_PATH);
  970. X
  971. X    btu_limit = BTU_left - btu;
  972. X    move_ind = 0;
  973. X    move_auto = 2;
  974. X    move_stat = 0;
  975. X    moveauto_next();
  976. X    return 0;`009/* no prompt */
  977. X`125
  978. X
  979. X
  980. Xstatic int C_path(char *comm, char *param)`032
  981. X`123
  982. X    char buffer`091COMMAND_SIZE`093,buffer2`091ERROR_LEN`093;
  983. X    char path`091MAX_MOVE_PATH+2`093;
  984. X    sector_data *from,*tar,*B = dump_database.sectors;
  985. X    cost_table costtable;
  986. X    dir_table dirtable;
  987. X    int temp_X,temp_Y;
  988. X
  989. X    if (!stepper(¶m,buffer,sizeof(buffer)) `124`124 StrEQ(buffer,"?",0))
  990. V `123
  991. X`009write_line("Usage: path from target",E_none,NULL);
  992. X`009return 1;
  993. X    `125
  994. X
  995. X    if(sscanf(buffer,"%d,%d",&start_X,&start_Y) != 2) `123
  996. X`009write_line("Give sector in format X,Y",E_tool,buffer);
  997. X`009return 1;
  998. X    `125
  999. X
  1000. X    if(!(from = Locate(&dump_database,start_X,start_Y))) `123
  1001. X`009write_line("Sector not found",E_tool,buffer);
  1002. X`009return 1;
  1003. X    `125
  1004. X
  1005. X    if(!stepper(¶m,buffer,sizeof(buffer)) `124`124`032
  1006. X`009sscanf(buffer,"%d,%d",&tar_X,&tar_Y) != 2) `123
  1007. X`009write_line("Give sector in format X,Y",E_tool,buffer);
  1008. X`009return 1;
  1009. X    `125
  1010. X
  1011. X    if(!(tar = Locate(&dump_database,tar_X,tar_Y))) `123
  1012. X`009write_line("Sector not found",E_tool,buffer);
  1013. X`009return 1;
  1014. X    `125
  1015. X
  1016. X    calculate_cost(&dump_database,start_X,start_Y,
  1017. X`009costtable,dirtable,MAX_MOVE_PATH);
  1018. X
  1019. X    if (costtable`091tar - B`093 > 1000) `123
  1020. X`009sprintf(buffer2,"No path from %d,%d to %d,%d",
  1021. X`009    start_X,start_Y,tar_X,tar_Y);
  1022. X`009write_line(buffer2,E_none,NULL);
  1023. X`009return 1;
  1024. X    `125
  1025. X
  1026. X    give_path(&dump_database,dirtable,path,tar - B,&temp_X,&temp_Y);
  1027. X    if (temp_X != start_X `124`124 temp_Y != start_Y) `123
  1028. X`009write_line("Something is wrong with path",E_tool,NULL);
  1029. X`009return 1;
  1030. X    `125
  1031. X
  1032. X    sprintf(buffer2,"Best path from %d,%d to %d,%d is %s",
  1033. X`009start_X,start_Y,tar_X,tar_Y,path);
  1034. X    write_line(buffer2,E_none,NULL);
  1035. X    sprintf(buffer2,"with cost %.2f (lengt %d).",
  1036. X`009costtable`091tar - B`093,strlen(path));
  1037. X    write_line(buffer2,E_none,NULL);
  1038. X    return 1;
  1039. X`125
  1040. X
  1041. Xstatic int C_autodist(char *comm, char *param)`032
  1042. X`123
  1043. X    dump_fields array`091MAX_ARGS`093;
  1044. X    char buffer`091COMMAND_SIZE`093;
  1045. X    sector_data *tar;
  1046. X    int btu,var = -1,targ;
  1047. X
  1048. X    if (*param == '\0' `124`124 StrEQ(param,"?",0)) `123
  1049. X`009write_line("Usage: autodistribute area ?selector X,Y btu =$var",
  1050. X`009    E_none,NULL);
  1051. X`009write_line("       autodistribute area ?selector X,Y btu +$var",
  1052. X`009    E_none,NULL);
  1053. X
  1054. X`009write_line("       autodistribute area ?selector dc_area ?selector btu =
  1055. V$var",
  1056. X`009    E_none,NULL);
  1057. X`009write_line("       autodistribute area ?selector dc_area ?selector btu +
  1058. V$var",
  1059. X`009    E_none,NULL);
  1060. X
  1061. X`009return 1;
  1062. X    `125
  1063. X    InitSelector(dist_table);
  1064. X
  1065. X    stepper(¶m,buffer,sizeof(buffer));
  1066. X    if (!Base(&dump_database,dist_table,buffer)) return 1; /* reask prompt *
  1067. V/
  1068. X
  1069. X    stepper(¶m,buffer,sizeof(buffer));
  1070. X    if (*buffer == '?') `123
  1071. X`009if (!Filter(&dump_database,dist_table,buffer)) return 1; /* reask prompt
  1072. V */
  1073. X`009stepper(¶m,buffer,sizeof(buffer));
  1074. X    `125
  1075. X
  1076. X    if(sscanf(buffer,"%d,%d",&tar_X,&tar_Y) != 2) `123
  1077. X`009targ = 0;
  1078. X`009InitSelector(dist_targ_table);
  1079. X
  1080. X`009if (!Base(&dump_database,dist_targ_table,buffer)) return 1; /* reask pro
  1081. Vmpt */
  1082. X
  1083. X`009stepper(¶m,buffer,sizeof(buffer));
  1084. X`009if (*buffer == '?') `123
  1085. X`009    if (!Filter(&dump_database,dist_targ_table,buffer)) return 1; /* rea
  1086. Vsk prompt */
  1087. X`009    stepper(¶m,buffer,sizeof(buffer));
  1088. X`009`125
  1089. X    `125 else `123
  1090. X`009stepper(¶m,buffer,sizeof(buffer));
  1091. X`009targ = 1;
  1092. X    `125
  1093. X
  1094. X    if(targ && !(tar = Locate(&dump_database,tar_X,tar_Y))) `123
  1095. X`009write_line("Sector not found",E_tool,buffer);
  1096. X`009return 1;
  1097. X    `125
  1098. X
  1099. X    btu = BTU_left - 20;
  1100. X    if (btu < 0) `123
  1101. X`009write_line("No BTU's for distribute!",E_tool,NULL);
  1102. X`009return 1;
  1103. X    `125
  1104. X
  1105. X    if (buffer`0910`093 && (sscanf(buffer,"%d",&btu) != 1 `124`124
  1106. X`009    btu > BTU_left)) `123
  1107. X`009write_line("No such btu",E_tool,buffer);
  1108. X`009return 1;
  1109. X    `125
  1110. X
  1111. X    if(stepper(¶m,buffer,sizeof(buffer)) &&
  1112. X`009init_var(&var,buffer) == -1) return 1;
  1113. X
  1114. X    btu_limit = BTU_left - btu;
  1115. X    dist_count = 0;
  1116. X    dist_auto = 1;
  1117. X    dist_targ = targ;
  1118. X    dist_var = var;
  1119. X
  1120. X    dist_cur = -1;
  1121. X    next_distribute();
  1122. X    return 0; /* no prompt */
  1123. X`125
  1124. X
  1125. Xstatic int C_save(char *comm, char *param)`032
  1126. X`123
  1127. X    dump_fields array`091MAX_ARGS`093;
  1128. X    char buffer`091COMMAND_SIZE`093;
  1129. X    sector_data *tar;
  1130. X    int btu;
  1131. X
  1132. X    if (*param == '\0' `124`124 StrEQ(param,"?",0)) `123
  1133. X`009write_line("Usage: save file",E_none,NULL);
  1134. X`009return 1;
  1135. X    `125
  1136. X
  1137. X    write_database(param,&dump_database, dump_area);
  1138. X
  1139. X    return 1;
  1140. X`125
  1141. X
  1142. Xstatic int C_distribute(char *comm, char *param)`032
  1143. X`123
  1144. X    cost_table costtable;
  1145. X    dir_table dirtable;
  1146. X    char *oldpath;
  1147. X    int temp_X,temp_Y,var = -1;
  1148. X    char buffer`091COMMAND_SIZE`093;
  1149. X    sector_data *tar,*from,*B = dump_database.sectors;
  1150. X
  1151. X    if (*param == '\0' `124`124 StrEQ(param,"?",0)) `123
  1152. X`009write_line("Usage: distribute from to =$var",E_none,NULL);
  1153. X`009write_line("       distribute from to +$var",E_none,NULL);
  1154. X`009return 1;
  1155. X    `125
  1156. X
  1157. X    if(!stepper(¶m,buffer,sizeof(buffer)) `124`124
  1158. X`009sscanf(buffer,"%d,%d",&start_X,&start_Y) != 2) `123
  1159. X`009write_line("Give from-sector in format X,Y",E_tool,buffer);
  1160. X`009return 1;
  1161. X    `125
  1162. X
  1163. X    if (!(from = Locate(&dump_database,start_X,start_Y))) `123
  1164. X`009write_line("Sector not found",E_tool,buffer);
  1165. X`009return 1;
  1166. X    `125
  1167. X
  1168. X    oldpath = (*from)`091F_dist_path`093.U_string;
  1169. X    if (oldpath == UNKNOWN_string) `123
  1170. X`009write_line("No enaugh information for sector",E_tool,buffer);
  1171. X`009return 1;
  1172. X    `125
  1173. X
  1174. X    if(!stepper(¶m,buffer,sizeof(buffer)) `124`124
  1175. X`009sscanf(buffer,"%d,%d",&tar_X,&tar_Y) != 2) `123
  1176. X`009write_line("Give to-sector in format X,Y",E_tool,buffer);
  1177. X`009return 1;
  1178. X    `125
  1179. X
  1180. X    if(!(tar = Locate(&dump_database,tar_X,tar_Y))) `123
  1181. X`009write_line("Sector not found",E_tool,buffer);
  1182. X`009return 1;
  1183. X    `125
  1184. X
  1185. X    calculate_cost(&dump_database,start_X,start_Y,
  1186. X`009costtable,dirtable,MAX_DIST_PATH);
  1187. X
  1188. X    if (costtable`091tar - B`093 > 1000) `123
  1189. X`009sprintf(buffer,"No path from %d,%d to %d,%d",
  1190. X`009    start_X,start_Y,tar_X,tar_Y);
  1191. X`009write_line(buffer,E_tool,NULL);
  1192. X`009return 1;
  1193. X    `125
  1194. X
  1195. X    give_path(&dump_database,dirtable,dist_path,tar - B,&temp_X,&temp_Y);
  1196. X    if (temp_X != start_X `124`124 temp_Y != start_Y) `123
  1197. X`009write_line("Something is wrong with path",E_tool,NULL);
  1198. X`009return 1;
  1199. X    `125
  1200. X
  1201. X    if (oldpath && (StrEQ(oldpath,dist_path,0) `124`124
  1202. X`009(StrEQ(oldpath,"_",0) && StrEQ(dist_path,"",0)))) `123
  1203. X`009sprintf(buffer,"Path from %d,%d to %d,%d OK!",
  1204. X`009start_X,start_Y,tar_X,tar_Y);
  1205. X`009write_line(buffer,E_none,NULL);
  1206. X`009return 1; /* prompt */
  1207. X    `125
  1208. X
  1209. X    if (empiretool_cancel) `123
  1210. X`009write_line("Canceled.",E_tool,NULL);
  1211. X`009empiretool_cancel = 0;
  1212. X`009return 1;
  1213. X    `125
  1214. X
  1215. X    if(stepper(¶m,buffer,sizeof(buffer)) &&
  1216. X`009init_var(&var,buffer) == -1) return 1;
  1217. X
  1218. X    dist_auto = 0;
  1219. X    dist_var = var;
  1220. X    sprintf(buffer,"distribute %d,%d %sh",
  1221. X`009start_X,start_Y,dist_path);
  1222. X    feed_command(buffer,parse_dump_dist);
  1223. X
  1224. X    return 0; /* no prompt */
  1225. X`125
  1226. X
  1227. Xstatic int C_desig(char *comm, char *param)`032
  1228. X`123
  1229. X    char buffer`091COMMAND_SIZE`093;
  1230. X    sector_data *tar;
  1231. X    int var = -1;
  1232. X
  1233. X    if (*param == '\0' `124`124 StrEQ(param,"?",0)) `123
  1234. X`009write_line("Usage: designate sector designation =$var",E_none,NULL);
  1235. X`009write_line("       designate sector designation +$var",E_none,NULL);
  1236. X`009return 1;
  1237. X    `125
  1238. X
  1239. X    if(!stepper(¶m,buffer,sizeof(buffer)) `124`124
  1240. X`009sscanf(buffer,"%d,%d",&des_X,&des_Y) != 2) `123
  1241. X`009write_line("Give sector in format X,Y",E_tool,buffer);
  1242. X`009return 1;
  1243. X    `125
  1244. X
  1245. X    if (!(tar = Locate(&dump_database,des_X,des_Y))) `123
  1246. X`009write_line("Sector not found",E_tool,buffer);
  1247. X`009return 1;
  1248. X    `125
  1249. X
  1250. X    if ((*tar)`091F_eff`093.U_num == UNKNOWN_num) `123
  1251. X`009write_line("No enaugh information for sector",E_tool,buffer);
  1252. X`009return 1;
  1253. X    `125
  1254. X
  1255. X    if(!stepper(¶m,buffer,sizeof(buffer)) `124`124
  1256. X`009strlen(buffer) != 1 `124`124
  1257. X`009sscanf(buffer,"%c",&des_C) != 1) `123
  1258. X`009write_line("Give designation in form D",E_tool,buffer);
  1259. X`009return 1;
  1260. X    `125
  1261. X
  1262. X    if(stepper(¶m,buffer,sizeof(buffer)) &&
  1263. X`009init_var(&var,buffer) == -1) return 1;
  1264. X
  1265. X    if (empiretool_cancel) `123
  1266. X`009write_line("Canceled.",E_tool,NULL);
  1267. X`009empiretool_cancel = 0;
  1268. X`009return 1;
  1269. X    `125
  1270. X
  1271. X    des_var = var;
  1272. X    des_explore = 0;
  1273. X    sprintf(buffer,"designate %d,%d %c",des_X,des_Y,des_C);
  1274. X    feed_command(buffer,parse_dump_desig);
  1275. X    return 0;
  1276. X`125
  1277. X
  1278. Xstatic int C_thre(char *comm, char *param)`032
  1279. X`123
  1280. X    char buffer`091COMMAND_SIZE`093;
  1281. X    char path`091MAX_MOVE_PATH+2`093;
  1282. X    sector_data *from;
  1283. X    int commodity,amount;
  1284. X    dump_fields field;
  1285. X    int var = -1;
  1286. X
  1287. X    if (!stepper(¶m,buffer,sizeof(buffer)) `124`124 StrEQ(buffer,"?",0))
  1288. V `123
  1289. X`009write_line("Usage: threshold com X,Y amount =$var",E_none,NULL);
  1290. X`009write_line("       threshold com X,Y amount +$var",E_none,NULL);
  1291. X`009return 1;
  1292. X    `125
  1293. X
  1294. X
  1295. X    if((field = MatchCom(buffer,&commodity)) == F_NULL) return 1;
  1296. X    thre_field = commodities`091commodity`093.thre;
  1297. X
  1298. X    if (thre_field == F_NULL) `123
  1299. X`009write_line("No such commodity",E_tool,buffer);
  1300. X`009return 1;
  1301. X    `125
  1302. X
  1303. X    if(!stepper(¶m,buffer,sizeof(buffer)) `124`124`032
  1304. X`009sscanf(buffer,"%d,%d",&thre_X,&thre_Y) != 2) `123
  1305. X`009write_line("Give sector in format X,Y",E_tool,buffer);
  1306. X`009return 1;
  1307. X    `125
  1308. X
  1309. X    if(!(from = Locate(&dump_database,thre_X,thre_Y))) `123
  1310. X`009write_line("Sector not found",E_tool,buffer);
  1311. X`009return 1;
  1312. X    `125
  1313. X
  1314. X    if ((*from)`091field`093.U_num == UNKNOWN_num `124`124 `032
  1315. X`009(*from)`091thre_field`093.U_num == UNKNOWN_num) `123
  1316. X`009write_line("Not enaugh data for that sector",E_tool,buffer);
  1317. X`009return 1;
  1318. X    `125
  1319. X
  1320. X    if(!stepper(¶m,buffer,sizeof(buffer)) `124`124`032
  1321. X`009sscanf(buffer,"%d",&thre_amount) != 1) `123
  1322. X`009write_line("No such amount",E_tool,buffer);
  1323. X`009return 1;
  1324. X    `125
  1325. X
  1326. X    if(stepper(¶m,buffer,sizeof(buffer)) &&
  1327. X`009init_var(&var,buffer) == -1) return 1;
  1328. X
  1329. X    if (empiretool_cancel) `123
  1330. X`009write_line("Canceled.",E_tool,NULL);
  1331. X`009empiretool_cancel = 0;
  1332. X`009return 1;
  1333. X    `125
  1334. X
  1335. X    thre_var = var;
  1336. X   `032
  1337. X    sprintf(buffer,"threshold %c %d,%d %d",
  1338. X`009commodities`091commodity`093.C,thre_X,thre_Y,thre_amount);
  1339. X    feed_command(buffer,parse_dump_thre);
  1340. X    return 0;`009/* no prompt */
  1341. X`125
  1342. X
  1343. Xstatic int C_compare(char *comm, char *param)`032
  1344. X`123
  1345. X    char buffer`091COMMAND_SIZE`093,area`091COMMAND_SIZE`093,
  1346. X`009database_name`091COMMAND_SIZE`093;
  1347. X    selector table;
  1348. X    int var = -1,i;
  1349. X    int ok = 1;
  1350. X
  1351. X    if (!stepper(¶m,buffer,sizeof(buffer)) `124`124 StrEQ(buffer,"?",0))
  1352. V `123
  1353. X`009write_line("Usage: compare file-name area ?selector... =$var",
  1354. X`009    E_none,NULL);
  1355. X`009write_line("       compare file-name area ?selector... +$var",
  1356. X`009    E_none,NULL);
  1357. X`009write_line("       compare old area ?selector... =$var",`032
  1358. X`009    E_none,NULL);
  1359. X`009write_line("       compare old area ?selector... +$var",`032
  1360. X`009    E_none,NULL);
  1361. X`009write_line("  \"old\" as file-name means old empiretool database",
  1362. X`009    E_none,NULL);
  1363. X`009return 1;
  1364. X    `125
  1365. X
  1366. X    strcpy(database_name,buffer);
  1367. X
  1368. X    if (!temp_database.sectors) `123
  1369. X`009if(!init_database(&temp_database)) `123
  1370. X`009    return 1;
  1371. X`009`125
  1372. X    `125 else reset_database(&temp_database);
  1373. X
  1374. X    if (StrEQ(database_name,"old",1)) `123
  1375. X`009update_database(&temp_database,&old_database);
  1376. X    `125 else `123
  1377. X`009if (!load_database(database_name,&temp_database,area,0)) return 1;
  1378. X    `125
  1379. X
  1380. X    InitSelector(table);
  1381. X
  1382. X    stepper(¶m,buffer,sizeof(buffer));
  1383. X    if (!Base(&temp_database,table,buffer)) return 1;
  1384. X
  1385. X    stepper(¶m,buffer,sizeof(buffer));
  1386. X    if (*buffer == '?') `123
  1387. X`009if (!Filter(&temp_database,table,buffer)) return 1; /* reask prompt */
  1388. X`009stepper(¶m,buffer,sizeof(buffer));
  1389. X    `125
  1390. X
  1391. X    if(init_var(&var,buffer) == -1) return 1;
  1392. X
  1393. X    for(i = 0; i < temp_database.count; i++) if (table`091i`093) `123
  1394. X`009int X = temp_database.sectors`091i`093`091F_x`093.U_num;
  1395. X`009int Y = temp_database.sectors`091i`093`091F_y`093.U_num;
  1396. X`009char des = temp_database.sectors`091i`093`091F_des`093.U_char;
  1397. X`009int own = temp_database.sectors`091i`093`091F_OWNED`093.U_bool;
  1398. X`009sector_data *sector = Locate(&dump_database,X,Y);
  1399. X`009if (!sector) `123
  1400. X`009    if (own == 1) `123
  1401. X`009`009char buffer`091ERROR_LEN`093;
  1402. X`009`009sprintf(buffer,
  1403. X`009`009    "Sector %d,%d (%c) not found from database, possible losed.",
  1404. X`009`009    X,Y,des);
  1405. X`009`009write_line(buffer,E_none,NULL);
  1406. X`009`009add_to_var(var,X,Y);
  1407. X`009`009ok = 0;
  1408. X`009    `125
  1409. X`009`125 else `123
  1410. X`009    if (own == 1 && (*sector)`091F_OWNED`093.U_bool == 0) `123
  1411. X`009`009char buffer`091ERROR_LEN`093;
  1412. X`009`009sprintf(buffer,"Sector %d,%d (%c) losed.",
  1413. X`009`009    X,Y,des);
  1414. X`009`009write_line(buffer,E_none,NULL);
  1415. X`009`009add_to_var(var,X,Y);
  1416. X`009`009ok = 0;
  1417. X`009    `125
  1418. X`009`125`009
  1419. X    `125
  1420. X   `032
  1421. X    if (ok) write_line("No losed sectors found",E_tool,NULL);
  1422. X
  1423. X    return 1;
  1424. X`125
  1425. X
  1426. Xstatic int C_remember(char *comm, char *param)
  1427. X`123
  1428. X    int pos;
  1429. X    int oldcount = dump_database.count;
  1430. X
  1431. X    if (StrEQ(param,"?",0)) `123
  1432. X`009write_line("Usage: remember",E_none,NULL);
  1433. X`009return 1;
  1434. X    `125
  1435. X
  1436. X    if (!old_database.sectors) `123
  1437. X`009write_line("No old database for remembering",E_tool,NULL);
  1438. X`009return 1;
  1439. X    `125
  1440. X   `032
  1441. X    if (!temp_database.sectors) `123
  1442. X`009if(!init_database(&temp_database)) return 1;`009/* FAILED */
  1443. X    `125 else reset_database(&temp_database);
  1444. X   `032
  1445. X    /* Make copy so we can modify it */
  1446. X    update_database(&temp_database,&old_database);
  1447. X
  1448. X    /* What sectors haven't current dump we don't owned */
  1449. X
  1450. X    for (pos = 1; pos < temp_database.count; pos++) `123
  1451. X`009if (temp_database.sectors`091pos`093`091F_OWNED`093.U_bool != UNKNOWN_bo
  1452. Vol
  1453. X`009    && temp_database.sectors`091pos`093`091F_OWNED`093.U_bool) `123
  1454. X
  1455. X`009    temp_database.sectors`091pos`093`091F_OWNED`093.U_bool = UNKNOWN_boo
  1456. Vl;
  1457. X`009    temp_database.sectors`091pos`093`091F_own`093.U_num = UNKNOWN_num;
  1458. X`009`125
  1459. X    `125
  1460. X
  1461. X    /* add current up of date data to this old database */
  1462. X    update_database(&temp_database,&dump_database);
  1463. X    /* and then move this database to dump database`032
  1464. X       (updated data is taken from dump_database so temp_database dont
  1465. X        overwrite now right data from dump_database) */
  1466. X    update_database(&dump_database,&temp_database);
  1467. X    check_visual();
  1468. X
  1469. X    `123`009char buffer`09130`093;
  1470. X`009sprintf(buffer,"%d sectors added", dump_database.count - oldcount);
  1471. X`009write_line("Old database remembered",E_tool,buffer);
  1472. X    `125
  1473. X    return 1;
  1474. X`125
  1475. X
  1476. X/*  VISUAL mode ********************************************************** *
  1477. V/
  1478. X
  1479. Xstatic int visual_X = 0, visual_Cx = 0;
  1480. Xstatic int visual_Y = 0, visual_Cy = 0;
  1481. Xstatic int visual_on = 0;
  1482. X
  1483. Xstatic void visual_update(int Cx,int cY);
  1484. Xstatic void visual_cursor(int Cx,int cY);
  1485. X
  1486. X
  1487. Xstatic void VS_up`009(struct screen_data *screen,
  1488. X`009prompt_type PR)
  1489. X`123
  1490. X    count_new(visual_X,visual_Y,0,-1,&visual_X,&visual_Y);
  1491. X    visual_cursor(visual_X,visual_Y);
  1492. X`125
  1493. X
  1494. Xstatic void VS_down`009(struct screen_data *screen,
  1495. X`009prompt_type PR)
  1496. X`123
  1497. X    count_new(visual_X,visual_Y,0,1,&visual_X,&visual_Y);
  1498. X    visual_cursor(visual_X,visual_Y);
  1499. X`125
  1500. X
  1501. Xstatic void VS_left`009(struct screen_data *screen,
  1502. X`009prompt_type PR)
  1503. X`123
  1504. X    count_new(visual_X,visual_Y,-1,0,&visual_X,&visual_Y);
  1505. X    visual_cursor(visual_X,visual_Y);
  1506. X`125
  1507. X
  1508. Xstatic void VS_right`009(struct screen_data *screen,
  1509. X`009prompt_type PR)
  1510. X`123
  1511. X    count_new(visual_X,visual_Y,1,0,&visual_X,&visual_Y);
  1512. X    visual_cursor(visual_X,visual_Y);
  1513. X`125
  1514. X
  1515. Xstatic void VS_return`009(struct screen_data *screen,
  1516. X`009prompt_type PR)
  1517. X`123
  1518. X    visual_quit();
  1519. X`125
  1520. X
  1521. Xstatic void VS_key(struct screen_data  *screen, prompt_type PR)
  1522. X`123
  1523. X
  1524. X`125
  1525. X
  1526. Xstatic void visual_topic(void)
  1527. X`123
  1528. X
  1529. X    screen_clear(P_screen,prompts`091P_screen`093.screen);
  1530. X`125
  1531. X
  1532. X#define VISUAL_SCROLL 21
  1533. X#define SH_TOP 2
  1534. X
  1535. Xstatic void visual_cursor(int x, int y)
  1536. X`123
  1537. X    char sbuffer`09110`093,lbuffer`09120`093;
  1538. X    int Xlen = prompts`091P_screen`093.screen -> Xmax - 32;
  1539. X    int Ylen = VISUAL_SCROLL -3 - 2*SH_TOP;
  1540. X    sector_data *sector;
  1541. X
  1542. X    int X1 = visual_Cx - Xlen/2;
  1543. X    int X2 = visual_Cx + Xlen/2;
  1544. X    int Y1 = visual_Cy - Ylen/2;
  1545. X    int Y2 = visual_Cy + Ylen/2;
  1546. X
  1547. X    if (x < X1 `124`124 x > X2 `124`124 y < Y1 `124`124 y > Y2) `123
  1548. X`009visual_Cx = x;
  1549. X`009visual_Cy = y;
  1550. X
  1551. X`009visual_update(visual_Cx,visual_Cy);
  1552. X
  1553. X`009X1 = visual_Cx - Xlen/2;
  1554. X`009X2 = visual_Cx + Xlen/2;
  1555. X`009Y1 = visual_Cy - Ylen/2;
  1556. X`009Y2 = visual_Cy + Ylen/2;
  1557. X
  1558. X    `125
  1559. X
  1560. X    sprintf(lbuffer,"Sec: %3d,%-3d",x,y);
  1561. X    screen_write(P_screen,Xlen+10,3,0,lbuffer);
  1562. X
  1563. X    sector = Locate(&dump_database,x,y);
  1564. X
  1565. X    if (sector) Text(sector,F_des,sbuffer);
  1566. X    else sbuffer`0910`093 = '\0';
  1567. X    sprintf(lbuffer,"Des:   %1s",sbuffer);
  1568. X    screen_write(P_screen,Xlen+10,4,0,lbuffer);
  1569. X
  1570. X    if (sector) Text(sector,F_civ,sbuffer);
  1571. X    else sbuffer`0910`093 = '\0';
  1572. X    sprintf(lbuffer,"Civ:   %4s",sbuffer);
  1573. X    screen_write(P_screen,Xlen+10,5,0,lbuffer);
  1574. X
  1575. X    if (sector) Text(sector,F_mil,sbuffer);
  1576. X    else sbuffer`0910`093 = '\0';
  1577. X    sprintf(lbuffer,"Mil:   %4s",sbuffer);
  1578. X    screen_write(P_screen,Xlen+10,6,0,lbuffer);
  1579. X
  1580. X    if (sector && (*sector)`091F_OWNED`093.U_bool != UNKNOWN_bool &&
  1581. X`009(*sector)`091F_OWNED`093.U_bool) strcpy(lbuffer,"Owned");
  1582. X    else strcpy(lbuffer,"     ");;
  1583. X    screen_write(P_screen,Xlen+10,7,0,lbuffer);
  1584. X
  1585. X    if (sector) Text(sector,F_own,sbuffer);
  1586. X    else sbuffer`0910`093 = '\0';
  1587. X    sprintf(lbuffer,"Owner: %4s",sbuffer);
  1588. X    screen_write(P_screen,Xlen+10,8,0,lbuffer);
  1589. X
  1590. X    screen_prompt(P_screen, x - X1 + 4, y - Y1 + 2 + SH_TOP);
  1591. X`125
  1592. X
  1593. X
  1594. Xstatic void visual_update(int Cx, int Cy)
  1595. X`123
  1596. X    char line`091MAX_X+10`093, temp`09110`093, data`091MAX_X+10`093;
  1597. X    char tops`091SH_TOP`093`091MAX_X+1`093;
  1598. X    selector table;
  1599. X    int x,y,i;
  1600. X    int X1 = (-MAX_X)/2,X2=MAX_X/2-1,
  1601. X`009Y1= (-MAX_Y)/2,Y2=MAX_Y/2-1;
  1602. X    int Xlen = prompts`091P_screen`093.screen -> Xmax - 32;
  1603. X    int Ylen = VISUAL_SCROLL -3 - 2*SH_TOP;
  1604. X
  1605. X    sprintf(line,"%3d,%-3d",Cx,Cy);
  1606. X    screen_write(P_screen,1,1,0,"Center: ");
  1607. X    screen_write(P_screen,9,1,SM_BOLD,line);
  1608. X
  1609. X    X1 = Cx - Xlen/2;
  1610. X    X2 = Cx + Xlen/2;
  1611. X    Y1 = Cy - Ylen/2;
  1612. X    Y2 = Cy + Ylen/2;
  1613. X
  1614. X    for (x = X1; x <= X2; x++) `123
  1615. X`009sprintf(temp,"%2d",x);
  1616. X`009for (i = 0; i < SH_TOP; i++) tops`091i`093`091x-X1`093 = temp`091i`093;
  1617. X    `125
  1618. X    for (i = 0; i < SH_TOP; i++) tops`091i`093`091X2-X1+1`093 = '\0';
  1619. X
  1620. X    for (i = 0; i < SH_TOP; i++) `123
  1621. X`009sprintf(line,"   %s",tops`091i`093);
  1622. X`009screen_write(P_screen,1,i+2,0,line);
  1623. X    `125
  1624. X
  1625. X    for (y = Y1; y <= Y2; y++) `123
  1626. X`009char tmp1`09110`093,tmp2`09110`093;
  1627. X`009for (x = X1; x <= X2; x++) `123
  1628. X`009    int XR,YR;
  1629. X`009    unsigned char s = ' ';
  1630. X`009    sector_data *temp;
  1631. X
  1632. X`009    count_new(x,y,0,0,&XR,&YR);
  1633. X
  1634. X`009    temp  = Locate(&dump_database,XR,YR);
  1635. X`009    if (temp) `123
  1636. X`009`009int I = temp - dump_database.sectors;
  1637. X`009`009s = (*temp)`091F_des`093.U_char;
  1638. X`009    `125
  1639. X`009    data`091x-X1`093=s;`009   `032
  1640. X`009`125
  1641. X`009data`091X2-X1+1`093 = '\0';
  1642. X`009sprintf(tmp1,"%2d",y); tmp1`091SH_TOP`093 = '\0';
  1643. X`009sprintf(tmp2,"%-2d",y); tmp2`091SH_TOP`093 = '\0';
  1644. X`009sprintf(line,"%2s %s %2s",tmp1,data,tmp2);
  1645. X`009screen_write(P_screen, 1, y - Y1 + 2 + SH_TOP, 0,line);
  1646. X    `125
  1647. X
  1648. X    for (x = X1; x <= X2; x++) `123
  1649. X`009sprintf(temp,"%-2d",x);
  1650. X`009for (i = 0; i < SH_TOP; i++) tops`091i`093`091x-X1`093 = temp`091i`093;
  1651. X    `125
  1652. X    for (i = 0; i < SH_TOP; i++) tops`091i`093`091X2-X1+1`093 = '\0';
  1653. X
  1654. X    for (i = 0; i < SH_TOP; i++) `123
  1655. X`009sprintf(line,"   %s",tops`091i`093);
  1656. X`009screen_write(P_screen, 1 , i + Y2 - Y1 + 3 + SH_TOP, 0, line);
  1657. X    `125
  1658. X
  1659. X`125
  1660. X
  1661. Xstatic void visual_start (void)`032
  1662. X`123
  1663. X    static struct SK_entry K`091`093 =
  1664. X    `123
  1665. X`009`123 SK_up,    VS_up `125,
  1666. X`009`123 SK_down,  VS_down `125,
  1667. X`009`123 SK_left,  VS_left `125,
  1668. X`009`123 SK_right, VS_right `125,
  1669. X`009`123 SK_return, VS_return `125,
  1670. X`009`123 SK_key,   VS_key `125,
  1671. X
  1672. X    `125;
  1673. X    static struct screen_data D =
  1674. X`009`123 0,0,0,0, NULL, NULL,`032
  1675. X`009    sizeof(K)/sizeof(struct SK_entry), &K,
  1676. X`009    VISUAL_SCROLL `125;
  1677. X
  1678. X    visual_Cx = 0; visual_X = 0;
  1679. X    visual_Cy = 0; visual_Y = 0;
  1680. X    visual_on = 1;
  1681. X   `032
  1682. X    screen_clear(P_screen,&D);
  1683. X    screen_write(P_screen,30,1,SM_REVERSE, "VISUAL mode");
  1684. X    change_prompt(P_screen);
  1685. X    visual_update(visual_Cx,visual_Cy);
  1686. X    visual_cursor(visual_X,visual_Y);
  1687. X`125
  1688. X
  1689. Xstatic int visual_quit(void)
  1690. X`123
  1691. X    if (visual_on) `123
  1692. X`009disable_prompt(P_screen,1);
  1693. X`009screen_clear(P_screen,NULL);
  1694. X`009change_prompt(P_tool);
  1695. X    `125
  1696. X    visual_on = 0;
  1697. X`125
  1698. X
  1699. Xstatic int C_visual(char *comm, char *param)`032
  1700. X`123
  1701. X
  1702. X    if (StrEQ(param,"?",0)) `123
  1703. X`009write_line("Usage: visual",E_none,NULL);
  1704. X`009write_line("       visual on/off",E_none,NULL);
  1705. X`009return 1;
  1706. X    `125
  1707. X    if (StrEQ(param,"",0) `124`124 StrEQ(param,"on",1)) visual_start();
  1708. X    else if (StrEQ(param,"off",1)) visual_quit();
  1709. X    else write_line("Bad argument",E_tool,param);
  1710. X    return 1;
  1711. X`125
  1712. X
  1713. X/* is called when dump_database is changed */
  1714. Xstatic void check_visual(void)
  1715. X`123
  1716. X    if (visual_on) `123
  1717. X`009visual_update(visual_Cx,visual_Cy);
  1718. X`009visual_cursor(visual_X,visual_Y);
  1719. X    `125
  1720. X`125
  1721. $ CALL UNPACK EMPIRETOOL.C;685 482063386
  1722. $ create/nolog 'f'
  1723. X$ CC/NOOPTIMIZE CLIENT,EMPIRETOOL
  1724. X$ LINK CLIENT,EMPIRETOOL,SYS$INPUT:/OPT
  1725. XMULTINET:MULTINET_SOCKET_LIBRARY/SHARE
  1726. XSYS$SHARE:VAXCRTL/SHARE
  1727. X$ EXIT
  1728. $ CALL UNPACK MAKE.COM;1 1801980739
  1729. $ EXIT
  1730.